<?php
	require_once (dirname(__FILE__)."/../config/Config.inc");
	require_once (dirname(__FILE__)."/../config/api.inc");
	//登录流程
		
	$phone =  getParam('phone','get');
	$pwd =  getParam('pwd','get');
	
	$result['parm'] = $_POST;
	if(empty($phone))
	{
		$result['status'] = '0';
		$result['msg'] = '请输入手机号';
		echoJSON($result);
		exit;
	}
	
	if(empty($pwd))
	{
		$result['status'] = '0';
		$result['msg'] = '请输入密码';
		echoJSON($result);
		exit;
	}
	
	
	unset($query);
	$query['loginname'] = $phone;
	
	if(!$userinfo = _User::getUserInfo($query))
	{
		$result['status'] = '0';
		$result['msg'] = '手机号未注册';
		echoJSON($result);
		exit;
	}
	else
	{
		if(md5($pwd) == $userinfo['password'])
		{
			//更新登录次数及ip
			if($userinfo['status'] == '1')
			{
				unset($query,$data);
				$query['id'] = $userinfo['id'];
				$data['lastnums'] = $userinfo['lastnums'] + 1;
				$data['lasttime'] = time();
				$data['lastip'] = getClientIP();
				
				$data['loginkey'] = md5($data['lasttime'].$userinfo['id'].$data['lastnums'].$data['lastip'].'!@#$%^&*()!@#$EW');
				
				_User::setUserInfo($query,$data);
				
				unset($query);
				$query['id'] = $userinfo['id'];
				$userinfo = _User::getUserInfo($query);
				
				$result['info'] = $userinfo;
				
				$result['msg'] = '登录成功';
				$result['status'] = '1';
				echoJSON($result);
				exit;
			}
			else
			{
				$result['status'] = '0';
				$result['msg'] = '帐号被禁用';
				echoJSON($result);
				exit;
			}
		}
		else
		{
			$result['status'] = '0';
			$result['msg'] = '密码错误';
			echoJSON($result);
			exit;
		}
	}
	